import {Component, OnInit} from '@angular/core';
import {AddOrdOrderComponent} from '../add-ord-order.component';
import {ErrRes} from '../../../../../frame/global/err-res';
import {OrdOrder} from '../../ord-order.type';
import {Services} from '../../../../../frame/module/services';
import {HttpRequestClient} from '../../../../../frame/http-request-client/http-request-client';
import {UrlRou} from '../../../../../frame';

@Component({
    selector: 'app-main-add-ord-order',
    templateUrl: './main-add-ord-order.component.html',
    styleUrls: ['./main-add-ord-order.component.css']
})
export class MainAddOrdOrderComponent implements OnInit {

    errRes = new ErrRes();

    domain = new OrdOrder();

    extend = {
        domain: {
            default: () => {
                this.domain.serAudit = 'WAIT_SUBMIT';
                this.domain.serUsing = 'ENABLE';
            },
            serAudit: () => {
                return 'serAudit';
            },
        },
    };

    func = {
        save: {
            req: (event) => {
                Services.ordOrder.save(this.domain, this.func.save.callback).subscribe();
            },
            callback: {
                success: (result) => {
                    HttpRequestClient.router.navigate([UrlRou.ordOrder.list]);
                },
                error: (result) => {
                    this.errRes.error = result.error;
                    this.errRes.statusText = result.statusText;
                }
            }
        }
    };

    constructor(public addOrdOrder: AddOrdOrderComponent) {
        this.addOrdOrder.main = this;
    }

    ngOnInit() {
        this.extend.domain.default();
    }

}
